<template>
    <el-dialog :visible.sync="dialog" :title="isAdd ? '群主转让' : '群主转让'" append-to-body width="500px" center>
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px" append-to-body>
            <el-form-item label="群主转让为" prop="schId" >
                <el-select v-model="form.schId" clearable  filterable placeholder="请选择" style="width: 310px;">
                    <el-option
                        v-for="item in owner"
                        :key="item.schId"
                        :label="item.schName"
                        :value="item.schId">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>

        <div slot="footer" class="dialog-footer">
            <el-button type="text" @click="cancel">取消</el-button>
            <el-button :loading="loading" type="primary" @click="doSubmit" >确认</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { moveSave } from '@/api/data'
import { debounce } from '@/utils/validate'
export default {
    props: {
        isAdd: {
          type: Boolean,
          required: true
        },   
        owner:{
            type: Array,
            required: true
        },     
    },
    
    data() {
        return {
            loading: false, dialog: false,
            // owner:[],
            form: {
               schId:'',
               groupId:'',
            },
            rules: {
                schId:[
                    { required: true, trigger: 'blur',message: '请选选择需要转让的群主'},
                ]

            },
        }
    },
    methods: {
        cancel(){
            this.dialog  = false
        },
        doSubmit:debounce(function(){
            this.$refs['form'].validate((valid) => {
                if (valid){
                    moveSave(this.form.groupId,this.form.schId).then(res => {
                        if (res.code == 2000) {
                            this.$notify({
                                title: '群主转让成功',
                                type: 'success',
                                duration: 2500
                            })
                            this.dialog = false
                            this.form.schId = '' 
                            this.$parent.init()
                        }else{
                            this.$notify({
                                title: '群主转让失败',
                                type: 'error',
                                duration: 2500
                            })
                        }
                    })
                }else {
                    return false
                }

            })
        },500),
        
    },

}
</script>

<style scoped lang="scss">

</style>
